import com.mongodb.*;
import com.mongodb.client.MongoCollection;
import org.junit.Test;

/**
 * @author dinghao
 * @create 2021-09-18 17:10
 * @message
 */
public class MongDBTest {
    @Test
    public void test1(){
        Mongo mongoClient = new Mongo("192.168.1.193", 27017);

        DB mongoDatabase = mongoClient.getDB("dhtest");

        DBCollection mongoCollection = mongoDatabase.getCollection("dh");

        BasicDBObject basicDBObject = new BasicDBObject();

        basicDBObject.put("name","dinghao");
        basicDBObject.put("id","001");

        mongoCollection.insert(basicDBObject);

        BasicDBObject searchdh = new BasicDBObject();

        searchdh.put("id","001");

        DBCursor dbObjects = mongoCollection.find(searchdh);

        while (dbObjects.hasNext()) {
            System.out.println(dbObjects.next());
        }

    }
}
